﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Showroom.DAL;

namespace Showroom.BLL
{
    public class Users : _Users
    {
        public static Users GetUserByUserNamePassword(string userName, string password)
        {
            try
            {
                Users usr = new Users();
                usr.Query.AddResultColumn(Users.ColumnNames.ID);
                usr.Where.Deleted.Value = false;
                usr.Where.UserName.Value = userName;
                usr.Where.Password.Value = password;
                usr.Query.Top = 1;
                usr.Query.Load();

                return usr;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("Users.cs", "GetUserByUserNamePassword", ex.StackTrace);
                throw ex;
            }
        }

        public static void DeleteAllUsers()
        {
            try
            {
                Users usr = new Users();
                usr.LoadAll();
                for (int i = 0; i < usr.RowCount; i++)
                {
                    usr.Deleted = true;
                    usr.MoveNext();
                }
                usr.Save();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static void DeleteByID(int ID)
        {
            try
            {
                Users usr = new Users();
                usr.LoadByPrimaryKey(ID);
                usr.Deleted = true;
                usr.Save();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }


    }
}
